██████╗ ██████╗  █████╗ ████████╗ ██████╗  ██████╗ ██╗     ███████╗
██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔═══██╗██╔═══██╗██║ ██╔════╝
██║ ██║██████╔╝███████║ ██║ ██║ ██║██║ ██║██║ ███████╗
██║ ██║██╔══██╗██╔══██║ ██║ ██║ ██║██║ ██║██║ ╚════██║
██████╔╝██████╔╝██║ ██║ ██║ ╚██████╔╝╚██████╔╝███████╗███████║
╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚══════╝

██████╗ ███████╗ ██████╗██╗██████╗ ███████╗ ██╗ ██╗ ██████╗ ██████╗ ██╔══██╗██╔════╝██╔════╝██║██╔══██╗██╔════╝ ████████╗██╔═████╗██╔════╝ ██████╔╝█████╗ ██║ ██║██████╔╝█████╗ ╚██╔═██╔╝██║██╔██║███████╗ ██╔══██╗██╔══╝ ██║ ██║██╔═══╝ ██╔══╝ ████████╗████╔╝██║██╔═══██╗ ██║ ██║███████╗╚██████╗██║██║ ███████╗ ╚██╔═██╔╝╚██████╔╝╚██████╔╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝╚═╝╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ </pre>

Recipe #06 - Let's cook!

Another desert:

- Working with snapshots


Set variables


In [1]:
$dbatools1 = "localhost,1433"
$secureString = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $secureString
$database = "dbatools"
$snapshotName = "dbatools_snapshot"



Create new database snapshot


In [ ]:
New-DbaDbSnapshot -SqlInstance $dbatools1 -SqlCredential $cred -Database $database -Name $snapshotName

In [ ]:
Get-DbaDbSnapshot -SqlInstance $dbatools1 -SqlCredential $cred

In [ ]:
Get-DbaProcess -SqlInstance $dbatools1 -SqlCredential $cred -Database $database | Stop-DbaProcess

In [ ]:
Restore-DbaFromDatabaseSnapshot -SqlInstance $dbatools1 -SqlCredential $cred -Database $database -Snapshot $snapshotName

In [ ]:
# or -Database db1
Remove-DbaDbSnapshot -SqlInstance $dbatools1 -SqlCredential $cred -Snapshot $snapshotName